<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Encore\Admin\Config\Config;

class AppServiceProvider extends ServiceProvider {

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot() {
        //
        Schema::defaultStringLength(191);

//        \DB::listen(function ($query) {
//                $tmp = str_replace('?', '"'.'%s'.'"', $query->sql);
//                $qBindings = [];
//                foreach ($query->bindings as $key => $value) {
//                    if (is_numeric($key)) {
//                        $qBindings[] = $value;
//                    } else {
//                        $tmp = str_replace(':'.$key, '"'.$value.'"', $tmp);
//                    }
//                }
//                $tmp = vsprintf($tmp, $qBindings);
//                $tmp = str_replace("\\", "", $tmp);
//                //$fileName = storage_path('logs/sql/'.date('Y-m-d').'.log'); 
//                \Log::channel('sqllog')->info(' execution time: '.$query->time.'ms; '.$tmp."\n\n\t");
//
//            }
//        );

        $table = config('admin.extensions.config.table', 'admin_config');
        if (Schema::hasTable($table)) {
            Config::load();
        }
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register() {
        if (app()->isLocal()) {
            app()->register(\Barryvdh\Debugbar\ServiceProvider::class);
        }
    }

}
